/**
 * \* Created with IntelliJ IDEA.
 * \* User: 冯若航
 * \* Date: 2021/5/18
 * \* Time: 19:43
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class 每日温度 {
    public int[] dailyTemperatures(int[] temperatures) {
        int len=temperatures.length;
        int[] res=new int[len];
        for(int i=len-2;i>=0;i--){
            // j+= result[j]是利用已经有的结果进行跳跃
            for(int j=i+1;j<len;j+=res[j]){
                if(temperatures[j]>temperatures[i]){
                    res[i]=j-i;
                    break;
                }else if(res[j]==0){
                    //遇到0表示后面不会有更大的值，那当然当前值就应该也为0
                    res[i]=0;
                    break;
                }
            }
        }
        return res;
    }
}